//MAX-SAT GA problem-depended class
//$Id: maxsat_ga.h 140 2009-09-03 11:33:57Z Oleg.Bulychov $
#pragma once
#ifndef MAXSAT_GA_H
#define MAXSAT_GA_H

#include "../maxsat.h"

//__________________________________________________________________________________
class MaxSat_Solution_GA:
    public MaxSat_Solution
{
public:
    mutable double wheel_sector_;

    void cross(MaxSat_Solution_GA& genome, uniform_random& rnd)
    {//:simple one point crossover
        ASSERT_(dim_);
        ASSERT_(dim_ == genome.dim_);
        size_t size = dim_;
        //:NOTE: works if (size < INT_MAX)
        //TODO fix me
        size_t j = rnd.next_UInt(static_cast<unsigned>(size));
        for (size_t i = j; i < size; ++i)
        {
            std::swap(data_[i], genome.data_[i]);
        }
        changed_ = genome.changed_ = true;
    }

    void mutate(double mutationProbability, uniform_random& rnd)
    {
        for (size_t i = 0; i < dim_; ++i)
        {
            if (rnd.next_Double() < mutationProbability)
            {
                data_[i] = !data_[i];
                changed_ = true;
            }
        }
    }

    int get_Fitness() { return get_Cost(); }
};
//__________________________________________________________________________________

#endif
//EOF!
